package org.mclll.xwangplugin.plant.command;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mclll.xwangplugin.MclllCustom;
import org.mclll.xwangplugin.log.LogUtil;
import org.mclll.xwangplugin.plant.config.PlantConfig;

import java.util.Arrays;
import java.util.List;

/**
 * @author: geduo
 * @date: 2023/9/20 12:53
 */
public class PlantCommand implements TabExecutor {

    private final MclllCustom plugin;
    private final LogUtil log;
    private final List<String> COMMAND_LIST = Arrays.asList("reloadPlantGrow");

    public PlantCommand(MclllCustom plugin) {
        this.plugin = plugin;
        this.log = plugin.getLog();
    }

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        if (args.length > 0) {
            switch (args[0]) {
                case "reloadPlantGrow":
                    if (sender.isOp()) {
                        PlantConfig.reloadConfig(plugin.getDataFolder());
                        sender.sendMessage("重载植物生长控制配置文件成功");
                        log.info("重载植物生长控制配置文件成功");
                        return true;
                    }
                    break;
                default:
                    break;
            }
        }
        return false;
    }


    @Override
    public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        return COMMAND_LIST;
    }
}
